package com.xja.controller;

import com.xja.pojo.BlogUsers;
import com.xja.pojo.UserBlogDate;
import com.xja.pojo.UserProfitData;
import com.xja.service.UserBlogDataService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @作者:褚
 * @工程名:xja_blog
 * @方法:UserDataController
 * @创建时间:2022/4/24 19:24
 */
@Controller
@RequestMapping("userData")
public class UserBlogDataController {

    @Reference(url = "dubbo://localhost:20883")
    private UserBlogDataService userDataService;

    @RequestMapping("statistics")
    private String statistics(Model model, HttpSession session){

        BlogUsers user = (BlogUsers) session.getAttribute("user");
        List<UserBlogDate> userBlogData= userDataService.getUserBlogData(user.getUid());
        List<String> monthes = new ArrayList<>();
        List<Integer> articleCounts = new ArrayList<>();
        List<Integer> readsum = new ArrayList<>();
        List<Integer> commentsum = new ArrayList<>();
        List<Integer> collsum = new ArrayList<>();
        for (UserBlogDate userdata:userBlogData){
            monthes.add(userdata.getMonthes());
            articleCounts.add(userdata.getArticlecounts());
            readsum.add(userdata.getReadsum());
            commentsum.add(userdata.getCommentsum());
            collsum.add(userdata.getCollsum());
        }
        model.addAttribute("monthes",monthes);
        model.addAttribute("articleCounts",articleCounts);
        model.addAttribute("readsum",readsum);
        model.addAttribute("commentsum",commentsum);
        model.addAttribute("collsum",collsum);
        return "data";
    }

    @RequestMapping("statistics2")
    private String statistics2(Model model, HttpSession session){
        BlogUsers user = (BlogUsers) session.getAttribute("user");
        List<UserProfitData> userProfitData = userDataService.getUserProfitData(user.getUid());

        List<String> monthes = new ArrayList<>();
        List<Integer> counts = new ArrayList<>();

        for (UserProfitData userProfit:userProfitData){
            monthes.add(userProfit.getMonthes());
            counts.add(userProfit.getCounts());

        }
        model.addAttribute("monthes",monthes);
        model.addAttribute("counts",counts);
        return "data2";
    }
}
